//
//  LTFeedbackController.m
//  LTChat
//
//  Created by 俊松何 on 2017/7/28.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import "LTFeedbackController.h"

@interface LTFeedbackController ()<UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UITextField *contacttextField;

@property (weak, nonatomic) IBOutlet UITextView *contenttextView;

@property (weak, nonatomic) IBOutlet UILabel *tipLable;


@end

@implementation LTFeedbackController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.nametextField.backgroundColor = mainColor;
    self.contacttextField.backgroundColor = mainColor;
    self.contenttextView.backgroundColor = mainColor;
    
    self.contenttextView.delegate = self;
    
    self.tipLable.hidden = NO;
    
    
//    self.nameLable.text = NSLTLocalizedString(@"feedback.name", nil);
//    self.contactLable.text = NSLTLocalizedString(@"feedback.contacttype", nil);
//    self.contentLable.text = NSLTLocalizedString(@"feedback.content", nil);

}
- (void)textViewDidChange:(UITextView *)textView
{
    if(textView.text.length > 0)
    {
        self.tipLable.hidden = YES;
    }else
    {
        self.tipLable.hidden = NO;
    }
    
}

-(void)yd_layoutNavigation
{
    self.title = NSLTLocalizedString(@"set.question", nil);
    
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    but.size = CGSizeMake(44, 44);
    [but setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [but setTitle:NSLTLocalizedString(@"feedback.commit", nil) forState:UIControlStateNormal];
    [but addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    but.titleLabel.font = [UIFont systemFontOfSize:16];
    [but sizeToFit];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:but];
//    self.navigationItem.rightMargin = 5;

}
-(void)save{

    [self.view endEditing:YES];
    if(self.contacttextField.text.length == 0)
    {
        [MBProgressHUD showMessage:@"请输入联系方式"];
        return;
    }
    if(self.contenttextView.text.length == 0)
    {
        [MBProgressHUD showMessage:@"请输入反馈内容"];
        return;
    }
    
    [MBProgressHUD showProcessHud:@"" toView:self.view];
    NSString *contact = [NSString stringWithFormat:@"%@",self.contacttextField.text];
    NSDictionary *param = @{@"contact":contact,
                           @"content":self.contenttextView.text};
    [[MTHttpTool shareTool] postPath:@"/feedback/add" parameters:param success:^(MTBaseData *datamodel) {
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD showMessage:@"已提交"];
        [self.navigationController popViewControllerAnimated:YES];
    } failer:^(MTError *error) {
        [MBProgressHUD hideHUDForView:self.view];
    }];
    
    
}

@end
